Coalesce config.rustc and config.rustc_info
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jul 2016 22:25:46 +0000 (01:25 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jul 2016 23:14:30 +0000 (02:14 +0300)
12 files changed:
src/bin/cargo.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/ops/cargo_rustc/engine.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/ops/cargo_test.rs
src/cargo/util/config.rs
src/cargo/util/rustc.rs
tests/cargotest/lib.rs

index effef0490a6537b5b052b2e0d026fd1250c73da5..54abf14272bbfb285f84d0a6ea82c612266a64d7 100644 (file)
@@ -16,7 +16,6 @@ use cargo::core::shell::Verbosity;
 use cargo::execute_main_without_stdin;
 use cargo::util::{self, CliResult, lev_distance, Config, human, CargoResult};
 use cargo::util::CliError;
-use cargo::util::process_builder::process;
 
 #[derive(RustcDecodable)]
 pub struct Flags {
@@ -150,9 +149,8 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
     }
 
     if let Some(ref code) = flags.flag_explain {
-        try!(process(&*try!(config.rustc()))
-                 .arg("--explain").arg(code).exec()
-                 .map_err(human));
+        let mut procss = try!(config.rustc()).process();
+        try!(procss.arg("--explain").arg(code).exec().map_err(human));
         return Ok(None)
     }
 
index 2938e70cc7974bb4f875ece9f9924f1cdf6f0590..a5eba05cb7c22fc9ac55b605dbe44317647a9d38 100644 (file)
@@ -33,7 +33,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
     let packages = ops::get_resolved_packages(&resolve, registry);
 
     let profiles = try!(ws.current()).manifest().profiles();
-    let host_triple = try!(opts.config.rustc_info()).host.clone();
+    let host_triple = try!(opts.config.rustc()).host.clone();
     let mut cx = try!(Context::new(ws, &resolve, &packages, opts.config,
                                    BuildConfig {
                                        host_triple: host_triple,
index 17539c4d7ac48b9a17a7dc0e255730b70f0a034c..78d16365c53867810c532246482b33d8d3019d50 100644 (file)
@@ -443,7 +443,7 @@ fn scrape_build_config(config: &Config,
     let cfg_target = try!(config.get_string("build.target")).map(|s| s.val);
     let target = target.or(cfg_target);
     let mut base = ops::BuildConfig {
-        host_triple: try!(config.rustc_info()).host.clone(),
+        host_triple: try!(config.rustc()).host.clone(),
         requested_target: target.clone(),
         jobs: jobs,
         ..Default::default()
index c46b9170daafd28ed0c283d445c0b71cdb4ef3c0..4df862ffd5d61d6e9cb8a18e90af50ef55de795b 100644 (file)
@@ -8,7 +8,7 @@ use std::sync::Arc;
 use core::{Package, PackageId, PackageSet, Resolve, Target, Profile};
 use core::{TargetKind, Profiles, Metadata, Dependency, Workspace};
 use core::dependency::Kind as DepKind;
-use util::{self, CargoResult, ChainError, internal, Config, profile, Cfg, human};
+use util::{CargoResult, ChainError, internal, Config, profile, Cfg, human};
 
 use super::TargetConfig;
 use super::custom_build::{BuildState, BuildScripts};
@@ -166,7 +166,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                                       &self.build_config,
                                       kind,
                                       "RUSTFLAGS"));
-        let mut process = util::process(&*try!(self.config.rustc()));
+        let mut process = try!(self.config.rustc()).process();
         process.arg("-")
                .arg("--crate-name").arg("_")
                .arg("--print=file-names")
index b0fd0ea5e4f4c15f54b44f2ad8b501124b387422..071c7079d73d75360acde37c060ecb54041b3ddf 100644 (file)
@@ -113,7 +113,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
      .env("OPT_LEVEL", &profile.opt_level.to_string())
      .env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
      .env("HOST", cx.host_triple())
-     .env("RUSTC", &*try!(cx.config.rustc()))
+     .env("RUSTC", &try!(cx.config.rustc()).path)
      .env("RUSTDOC", &*try!(cx.config.rustdoc()));
 
      if let Some(links) = unit.pkg.manifest().links(){
index 76f5d3914f34f365231f0ea29b02db4dd78576cd..ec892392c9ef0073325596fdbfaa3a4cfd1a3f10 100644 (file)
@@ -41,7 +41,7 @@ impl CommandPrototype {
         Ok(CommandPrototype {
             builder: {
                 let mut p = match ty {
-                    CommandType::Rustc => process(&*try!(config.rustc())),
+                    CommandType::Rustc => try!(config.rustc()).process(),
                     CommandType::Rustdoc => process(&*try!(config.rustdoc())),
                     CommandType::Target(ref s) |
                     CommandType::Host(ref s) => process(s),
index d8b62319bf35935f1444036b56bf38adcdc9562e..60ff14c2b83937f81dcad34312bd24a7ee1cdf75 100644 (file)
@@ -352,7 +352,7 @@ fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
         try!(cx.rustflags_args(unit))
     };
     let fingerprint = Arc::new(Fingerprint {
-        rustc: util::hash_u64(&try!(cx.config.rustc_info()).verbose_version),
+        rustc: util::hash_u64(&try!(cx.config.rustc()).verbose_version),
         target: util::hash_u64(&unit.target),
         profile: util::hash_u64(&unit.profile),
         features: format!("{:?}", features),
index 76f9dc27f7c7c15cbe3c21ad8024453e1e758d02..2342352c51d6cae4605225649047c63c14114ceb 100644 (file)
@@ -204,7 +204,7 @@ fn rustc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
 
     let name = unit.pkg.name().to_string();
     if !cx.show_warnings(unit.pkg.package_id()) {
-        if try!(cx.config.rustc_info()).cap_lints {
+        if try!(cx.config.rustc()).cap_lints {
             rustc.arg("--cap-lints").arg("allow");
         } else {
             rustc.arg("-Awarnings");
index 5eb106b1e6f21a97219daede85997ea34c06ec51..52365c6e60d1a21565169ee7c3ccd3c03c830e46 100644 (file)
@@ -117,7 +117,7 @@ fn run_doc_tests(options: &TestOptions,
 
     // We don't build/rust doctests if target != host
     if let Some(target) = options.compile_opts.target {
-        if try!(config.rustc_info()).host != target {
+        if try!(config.rustc()).host != target {
             return Ok(errors);
         }
     }
index a225b6cfd1aa3a0a3dc5ebd78c9c7a48f6f529ae..2c7d1befb41efda8b66ab1b39c551ece98b640c3 100644 (file)
@@ -24,7 +24,7 @@ use self::ConfigValue as CV;
 pub struct Config {
     home_path: Filesystem,
     shell: RefCell<MultiShell>,
-    rustc_info: RefCell<Option<Rustc>>,
+    rustc: RefCell<Option<Rustc>>,
     values: RefCell<HashMap<String, ConfigValue>>,
     values_loaded: Cell<bool>,
     cwd: PathBuf,
@@ -42,7 +42,7 @@ impl Config {
         let mut cfg = Config {
             home_path: Filesystem::new(homedir),
             shell: RefCell::new(shell),
-            rustc_info: RefCell::new(None),
+            rustc: RefCell::new(None),
             cwd: cwd,
             values: RefCell::new(HashMap::new()),
             values_loaded: Cell::new(false),
@@ -96,11 +96,6 @@ impl Config {
         self.shell.borrow_mut()
     }
 
-    pub fn rustc(&self) -> CargoResult<Ref<Path>> {
-        let rustc = try!(self.rustc_info());
-        Ok(Ref::map(rustc, |r| r.path.as_ref()))
-    }
-
     pub fn rustdoc(&self) -> CargoResult<Ref<Path>> {
         if self.rustdoc.borrow().is_none() {
             *self.rustdoc.borrow_mut() = Some(try!(self.get_tool("rustdoc")));
@@ -108,12 +103,12 @@ impl Config {
         Ok(Ref::map(self.rustdoc.borrow(), |opt| opt.as_ref().map(AsRef::as_ref).unwrap()))
     }
 
-    pub fn rustc_info(&self) -> CargoResult<Ref<Rustc>> {
-        if self.rustc_info.borrow().is_none() {
+    pub fn rustc(&self) -> CargoResult<Ref<Rustc>> {
+        if self.rustc.borrow().is_none() {
             let path = try!(self.get_tool("rustc"));
-            *self.rustc_info.borrow_mut() = Some(try!(Rustc::new(path)));
+            *self.rustc.borrow_mut() = Some(try!(Rustc::new(path)));
         }
-        Ok(Ref::map(self.rustc_info.borrow(), |opt| opt.as_ref().unwrap()))
+        Ok(Ref::map(self.rustc.borrow(), |opt| opt.as_ref().unwrap()))
     }
 
     pub fn values(&self) -> CargoResult<Ref<HashMap<String, ConfigValue>>> {
index 8504e51e2633474a818ecda207407632e20a25f2..59a6e17e1fe56ec3e2706d39b09cc28485348c15 100644 (file)
@@ -1,6 +1,6 @@
 use std::path::PathBuf;
 
-use util::{self, CargoResult, internal, ChainError};
+use util::{self, CargoResult, internal, ChainError, ProcessBuilder};
 
 pub struct Rustc {
     pub path: PathBuf,
@@ -49,4 +49,8 @@ impl Rustc {
             cap_lints: cap_lints,
         })
     }
+
+    pub fn process(&self) -> ProcessBuilder {
+        util::process(&self.path)
+    }
 }
index 7053f483956bd79031b08aebd4d7024f0a299421..ffd094f9759fb5bfe07f214914bf800a77e3baf1 100644 (file)
@@ -21,11 +21,12 @@ extern crate log;
 use cargo::util::Rustc;
 use std::ffi::OsStr;
 use std::time::Duration;
+use std::path::PathBuf;
 
 pub mod support;
 pub mod install;
 
-thread_local!(pub static RUSTC: Rustc = Rustc::new("rustc").unwrap());
+thread_local!(pub static RUSTC: Rustc = Rustc::new(PathBuf::from("rustc")).unwrap());
 
 pub fn rustc_host() -> String {
     RUSTC.with(|r| r.host.clone())